package com.example.juc.kkb.synchronizedandlock;

/**
 * 老版写法
 */
public class MyCondition {
    private int number = 0;

    //⽼版写法
    public synchronized void increment() throws Exception {
        //1.判断
        if (number != 0) {
            this.wait();
        }
        //2.⼲活
        number++;
        System.out.println(Thread.currentThread().getName() + "\t" + number);
        //3通知
        this.notifyAll();
    }

    public synchronized void decrement() throws Exception {
        //1.判断
        if (number == 0) {
            this.wait();
        }
        //2.⼲活
        number--;
        System.out.println(Thread.currentThread().getName() + "\t" + number);
        //3通知
        this.notifyAll();
    }
}